<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css"
	href="../../layui/css/layui.css" media="all">
<script type="text/javascript" charset="gbk" src="gbk-jsp/ueditor.config.js"></script>
<script type="text/javascript" charset="gbk" src="gbk-jsp/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="gbk" src="gbk-jsp/lang/zh-cn/zh-cn.js"></script>
<title>增加政策</title>
<style>
	div,h1{
		text-align:center;
	}
</style>
</head>
<body>
	<form class="layui-form" action="../../policy/add.action" method="post">
		<h1>增加政策</h1>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">标题</label>
				<div class="layui-input-inline">
					<input type="text" name="policyName" id="policyName" required
						lay-verify="required" placeholder="标题" autocomplete="off" maxlength="10"
						class="layui-input">
				</div>
			</div>
		</div>
		<input type="hidden" name="policyComment" id="policyComment" required
			lay-verify="required" placeholder="内容" autocomplete="off" maxlength="1000"
			class="layui-input">
		<div>
			<div>
	    		<script id="editor" type="text/plain" style="width:1024px;height:500px;margin-left:250px;"></script>
			</div>
			<script type="text/javascript">
			    //实例化编辑器
			    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
			    var ue = UE.getEditor('editor');
				
			    function isFocus(e){
			        alert(UE.getEditor('editor').isFocus());
			        UE.dom.domUtils.preventDefault(e)
			    }
			    function setblur(e){
			        UE.getEditor('editor').blur();
			        UE.dom.domUtils.preventDefault(e)
			    }
			    function insertHtml() {
			        var value = prompt('插入html代码', '');
			        UE.getEditor('editor').execCommand('insertHtml', value)
			    }
			    function createEditor() {
			        enableBtn();
			        UE.getEditor('editor');
			    }
			    function getAllHtml() {
			        alert(UE.getEditor('editor').getAllHtml())
			    }
			    function setDisabled() {
			        UE.getEditor('editor').setDisabled('fullscreen');
			        disableBtn("enable");
			    }
			
			    function setEnabled() {
			        UE.getEditor('editor').setEnabled();
			        enableBtn();
			    }
			
			    function getText() {
			        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
			        var range = UE.getEditor('editor').selection.getRange();
			        range.select();
			        var txt = UE.getEditor('editor').selection.getText();
			        alert(txt)
			    }
			    function hasContent() {
			        var arr = [];
			        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
			        arr.push("判断结果为：");
			        arr.push(UE.getEditor('editor').hasContents());
			        alert(arr.join("\n"));
			    }
			    function setFocus() {
			        UE.getEditor('editor').focus();
			    }
			    function deleteEditor() {
			        disableBtn();
			        UE.getEditor('editor').destroy();
			    }
			    function disableBtn(str) {
			        var div = document.getElementById('btns');
			        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
			        for (var i = 0, btn; btn = btns[i++];) {
			            if (btn.id == str) {
			                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
			            } else {
			                btn.setAttribute("disabled", "true");
			            }
			        }
			    }
			    function enableBtn() {
			        var div = document.getElementById('btns');
			        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
			        for (var i = 0, btn; btn = btns[i++];) {
			            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
			        }
			    }
			
			    function getLocalData () {
			        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
			    }
			
			    function clearLocalData () {
			        UE.getEditor('editor').execCommand( "clearlocaldata" );
			        alert("已清空草稿箱")
			    }
			</script>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-inline">
					<input type="text" name="policyRemark" id="policyRemark" required
						lay-verify="required" maxlength="100" placeholder="备注"
						autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">可见公司</label>
				<div class="layui-input-block" id="filiale">
					
				</div>
			</div>
		</div>
		<input type="hidden" id="filIds" name="filIds">
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input onclick="add()" type="submit" class="layui-btn" lay-submit=""
					lay-filter="Add" value="发布政策">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	<script src="../../layui/layui.js"></script>
	<script src="../../res/mln/jquery-1.10.2.js"></script>
	<script type="text/javascript">
		layui.use('form', function(){
			var form = layui.form
			,layer = layui.layer
			,$ = layui.$;
			
			var url = "../../filiale/findAllFiliale.action";
			$.ajax({
				url:url,
				data:null,
				success:function(data){
					for(var i=0;i<data.length;i++){
						$("#filiale").append("<i><input type='checkbox' name='fil' value="+data[i].filId+" title="+data[i].filName+" lay-skin='primary' lay-filter='filter'></i>");
						form.render();
					}
				},
				dataType:"JSON"
			});
			form.on('submit(Add)',function(){
				parent.location.reload(); // 父页面刷新
			});
		});
		function add(){
			var bb="";
			var temp="";
			var a=document.getElementsByName("fil");
			for(var i=0;i<a.length; i++){
				if(a[i].checked){
					temp=a[i].value;
					if(bb==""){
						bb=temp;
					}else{
						bb=bb+","+temp;
					}
				}
			}
			$("#filIds").val(bb);
			
			var Content = UE.getEditor('editor').getContent();
			$("#policyComment").val(Content);
		}
	</script>
</body>
</html>